//
//  C_MovieListTableViewCell.m
//  音悦咖
//
//  Created by Best on 15/7/20.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "C_MovieListTableViewCell.h"

@implementation C_MovieListTableViewCell

- (void)awakeFromNib {
    // Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc
{
    [_bulletCountLabel release];
    [_videoNameLabel release];
    [_singerNameLabel release];
    [_pickCountLabel release];
    [_mainView release];
    [_movieImageView release];
    [_actorImageView release];
    [_pickImageView release];
    [_bulletImageView release];
    

    [_model release];
    [super dealloc];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self create];
    }
    return self;
}


- (void)create
{
    self.movieImageView  = [[UIImageView alloc] init];
    [self.contentView addSubview:self.movieImageView];
    [_movieImageView release];
    
    self.mainView = [[UIView alloc] init];
    [self.contentView addSubview:self.mainView];
    [_mainView release];
    
    self.videoNameLabel = [[UILabel alloc] init];
    [self.mainView addSubview:self.videoNameLabel];
    [_videoNameLabel release];
    
    self.actorImageView = [[UIImageView alloc] init];
    [self.mainView addSubview:self.actorImageView];
    [_actorImageView release];
    
    self.singerNameLabel = [[UILabel alloc] init];
    [self.mainView addSubview:self.singerNameLabel];
    [_singerNameLabel release];
    
    self.pickCountLabel = [[UILabel alloc] init];
    [self.mainView addSubview:self.pickCountLabel];
    [_pickCountLabel release];
    
    self.bulletCountLabel = [[UILabel alloc] init];
    [self.mainView addSubview:self.bulletCountLabel];
    [_bulletCountLabel release];
    
    self.bulletImageView = [[UIImageView alloc] init];
    [self.mainView addSubview:self.bulletImageView];
    [_bulletImageView release];
    
    self.pickImageView = [[UIImageView alloc] init];
    [self.mainView addSubview:self.pickImageView];
    [_pickImageView release];
    
    
}


- (void)myLayout
{
    [super layoutSubviews];
    
    CGFloat width = self.contentView.frame.size.width;
    CGFloat height = self.contentView.frame.size.height;
    
    self.movieImageView.frame = CGRectMake(5, 2, (width - 10) / 3, height - 4);
    
    self.mainView.frame = CGRectMake(self.movieImageView.frame.size.width + self.movieImageView.frame.origin.x + 5, self.movieImageView.frame.origin.y, width - 4 - (self.movieImageView.frame.size.width + self.movieImageView.frame.origin.x + 5), self.movieImageView.frame.size.height);
    
    self.videoNameLabel.frame = CGRectMake(0, 0, self.mainView.frame.size.width, self.frame.size.height / 3 );
//    [self.videoNameLabel sizeToFit];
    self.videoNameLabel.font = [UIFont systemFontOfSize:15];
    [self.videoNameLabel setTextAlignment:(NSTextAlignmentCenter)];
    
    
    self.actorImageView.frame = CGRectMake(0, self.videoNameLabel.frame.size.height + self.videoNameLabel.frame.origin.y, self.videoNameLabel.frame.size.height, self.videoNameLabel.frame.size.height );
    
    self.singerNameLabel.frame = CGRectMake(self.actorImageView.frame.size.width + self.actorImageView.frame.origin.x + 20, self.videoNameLabel.frame.size.height + self.videoNameLabel.frame.origin.y, 100, self.videoNameLabel.frame.size.height);
    self.singerNameLabel.textColor = COLOR_STOCHASTIC;
     self.singerNameLabel.font = [UIFont systemFontOfSize:15];
    
    self.pickImageView.frame = CGRectMake(0, self.actorImageView.frame.size.height + self.actorImageView.frame.origin.y, self.videoNameLabel.frame.size.height, self.videoNameLabel.frame.size.height - 5);
    
    self.pickCountLabel.frame = CGRectMake(self.pickImageView.frame.size.width + self.pickImageView.frame.origin.x + 10, self.pickImageView.frame.origin.y, 50, self.videoNameLabel.frame.size.height - 5);
    self.pickCountLabel.textColor = RGBA(180, 180, 180, 0.8);
    self.pickCountLabel.font = [UIFont systemFontOfSize:13];
    
    self.bulletImageView.frame = CGRectMake(self.pickCountLabel.frame.size.width + self.pickCountLabel.frame.origin.x + 30,self.pickCountLabel.frame.origin.y, self.videoNameLabel.frame.size.height, self.videoNameLabel.frame.size.height - 5);
    
    self.bulletCountLabel.frame = CGRectMake(self.bulletImageView.frame.size.width + self.bulletImageView.frame.origin.x + 10, self.bulletImageView.frame.origin.y, 50, self.videoNameLabel.frame.size.height - 5);
    self.bulletCountLabel.textColor = RGBA(180, 180, 180, 0.8);
    self.bulletCountLabel.font = [UIFont systemFontOfSize:13];
    
}



- (void)setModel:(C_MoviesListModel *)model
{
    if (_model !=model) {
        [_model release];
        _model = [model retain];
    }
    self.videoNameLabel.text = model.videoName;
   
    
    self.singerNameLabel.text = model.singerName;
   
    self.pickCountLabel.text = [model.pickCount description];
   
    self.bulletCountLabel.text = [model.bulletCount description];

    if ([model.mvList count] > 0) {
        [self.movieImageView setImageWithURL:[NSURL URLWithString:[model.mvList[0] objectForKey:@"picUrl"]] placeholderImage:[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"mvtemp", @"jpg")]];
    } else {
    self.movieImageView.image = [UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"mvtemp", @"jpg")];
    }
    self.actorImageView.image = [UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"actor@2x", @"png")];
    self.bulletImageView.image = [UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"bullet@2x", @"png")];
    self.pickImageView.image = [UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"player@2x", @"png")];
    
}

@end
